<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.cap.bts.framework.common.util.CodeTextUtils"  %>
<%@ page import="com.cap.bts.framework.usermgnt.dto.RoleQueryDto"  %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>经销商能力提升-角色与权限设置</title>
<META content="text/html; charset=UTF-8" http-equiv=Content-Type>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">  
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">  
<META HTTP-EQUIV="Expires" CONTENT="0"> 
<%@include file="../../../include/include.jsp"%>
<link rel="stylesheet" type="text/css" href="${csspath}/public.css"/>
<link rel="stylesheet" type="text/css" href="${csspath}/style_l.css"/>
<link rel="stylesheet" type="text/css" href="${csspath}/validationEngine.jquery.css"/>
<link rel="stylesheet" type="text/css" href="${csspath}/jquery.alerts.css" />
<script type="text/javascript" src="${jspath}/jquery/jquery-1.4.4.js"></script>
<script type="text/javascript" src="${jspath}/jquery/jquery.ui.min.js"></script>
<script type="text/javascript" src="${jspath}/jquery/jquery.blockUI.js"></script>
<script type="text/javascript" src="${jspath}/load_layer.js"></script>
<script type="text/javascript" src="${jspath}/public.js"></script> 
<script type="text/javascript" src="${jspath}/jquery/validate/jquery.validationEngine.js"></script>
<script type="text/javascript" src="${jspath}/jquery/validate/jquery.validationEngine-zh.js"></script>
<script type="text/javascript" src="${jspath}/jquery/jquery.ui.draggable.js"></script>
<script type="text/javascript" src="${jspath}/jquery/jquery.alerts.js"></script>

<script language="javascript">

$(function() {
	
	$("#roleType").val("${roleQueryDto.roleType}");
	$("#detailInfo").click(function() {
		var roleIds = $("input[name='roleIds'][type='radio']");
		var checkedRoleId = -1;
		for (i = 0; i < roleIds.length; i++) {
			if (roleIds[i].checked) {
				checkedRoleId = $(roleIds[i]).val();
				break;
			}
		}
		if (checkedRoleId == -1) {
			jAlert("请选择要查看的角色！", "提示信息");
			return;
		}
		location.href = "${webcontext}/dm/userperm/rolefunc/detail/" + checkedRoleId;
	}); 
	$("#update").click(function(){
		var roleIds = $("input[name='roleIds'][type='radio']");
		var checkedRoleId = -1;
		var brandId = -1;
		for (i = 0; i < roleIds.length; i++) {
			if (roleIds[i].checked) {
				checkedRoleId = $(roleIds[i]).val();
				var tr = $(roleIds[i]).parent().parent();
				brandId = $(tr).find(":hidden").val();
				break;
			}
		}
		if (checkedRoleId == -1) {
			jAlert("请选择要修改的角色！", "提示信息");
			return;
		}
		if (brandId == 0 || brandId == -1) {
			jAlert("您选择的不是品牌角色不能修改！", "提示信息");
			return;
		}
		location.href = "${webcontext}/dm/userperm/rolefunc/edit/" + checkedRoleId;
	});
	
	// 删除 
	$("#idelete").click(function() {
		var radioVal = $("input:radio:checked").val();
		if (radioVal != undefined) {
			jConfirm("确认删除此角色？", "操作提示", function(result) {
				if(result) {
					//查询是否有关联关系，		
					$.get("${webcontext}/dm/userperm/rolefunc/validateDelRole/" + radioVal, 
						   {},
						   function(msg){
							   if(msg){
								   //删除
								   $.get("${webcontext}/dm/userperm/rolefunc/delete/" + radioVal, 
										   {},
										   function(data,qq) {
											      if (data == "true") {										
														$("#queryform").submit();
												   }else {
														jAlert("删除失败！","操作提示");
						  			               }
									       }
								   );   
							   }else{
								   jAlert("不能删除正在使用中的角色！","操作提示");
							   }
						   }
					);
				}
			});
		}else{
			jAlert("请选择要删除的角色！","提示信息");
		}
	});	
	
  	$("#iadd").click(function(){
		$(this).attr("href","add");		
	});
  	
  	$("#export").click(function(){
  		var qform = $("#queryform");
  		var action = qform.attr("action");
  		var exportStr = action.substr(0,action.lastIndexOf("/")+1)+"export";
		$("#queryform").attr("action",exportStr);	
		document.queryform.submit();
		$("#queryform").attr("action",action);
	});
	
	$("#queryform").validationEngine();
	
	$("#queryform").submit(function(){
		if($("#queryform").validationEngine({returnIsValid:true})){
			return true;
		}
		return false;
	});
});

function search(){
	$("#queryform").attr("action","${webcontext}/dm/userperm/rolefunc/query");
	$("#queryform").submit();
}
</script>
</head>
<body>
	<!-- content -->
	<div id="content">
		<!-- wrap -->
		<div id="wrap">

			<!-- breadcrumb -->
			<div id="breadcrumb">
				<div class="left">
					<span>经销商能力提升</span>
					<span>&gt;</span>
					<span>角色与权限设置</span>
				</div>
			</div>
			<!-- /breadcrumb -->
			<!-- search_div -->
			<form:form id="queryform" name="queryform" action="${webcontext}/dm/userperm/rolefunc/query" method="post" modelAttribute="roleQueryDto">
			<div class="search_div">
				<div class="spliter h_10"></div>
				<table class="search_tab">
					<tr>
					  <td class="label">角色代码：</td>
					  <td><form:input id="roleCode" path="roleCode" cssClass="text validate[length[0,40]]"/></td>
					  <td class="label">角色名称：</td>
					  <td><form:input id="roleName" path="roleName" cssClass="text validate[length[0,100]]" /></td>
				  </tr>
					<tr>
						<td colspan="8" class="center2">
							<input type="submit" class="btn" value="查询"/>&nbsp;&nbsp;<input type="reset" class="btn" value="重置"/>
						</td>
					</tr>
				</table>
				<div class="spliter h_10"></div>
			</div>
			<!-- /search_div -->
			<div class="spliter h_10"></div>
			
						<!-- page_div -->
						<div class="page_div">
							<div class="page_info">
							<a id="iadd" class="add" href="#">新增</a>
							<a id="detailInfo" class="search" href="#">详情</a>
<!--                  			<a id="update" class="edit" href="#">修改</a>                  -->
                  			<a id="idelete" class="delete" href="#">删除</a>
<!--                  			<a id="export" class="export" href="#">导出</a>				-->
						</div>
						<%@include file="../../../common/headerpage.jsp"%>
						</div>
						<!-- /page_div -->
						<!-- data_div -->
						<div class="data_div">
							<table class="data_tab">
								<tr>
									<th>选择</th>
									<th>角色类型</th>
<!--			                        <th>角色代码</th>-->
			                        <th>角色名称</th>
									<th>最后授权日期</th>
									<th>最后授权人</th>
								</tr>
								<core:forEach items="${roleList}" var="role">
								<tr>
									<td class="align_m"><input type="radio" name="roleIds" value="${role.id}" /><input type="hidden" name="brandId" value="${role.brandId}" /></td>
<!--									<td>${role.roleTypeStr}</td>-->
									<td>${role.roleCode}</td>
									<td>${role.roleName}</td>									
									<td>
									<fmt:formatDate value="${role.lastAuthorizedDate}" pattern="yyyy-MM-dd"/>
									</td>
									<td>${role.lastAuthorizedByStr}</td>
								</tr>
								</core:forEach>
							</table>
						</div>
						<!-- /data_div -->
			            <!-- page_div -->
						<div class="page_div">
							<%@include file="../../../common/page.jsp"%>
						</div>
						<!-- /page_div -->
			</form:form>     
		</div>
		<!-- /wrap -->
	</div>
	<!-- /content -->
</body>
</html>